var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {
    value: !0
});
var i = t("Hint"),
n = t("Util"),
a = function() {
    function t() {
        this.recordingTime = 0,
        this.deltaTime = 0,
        this.videoPath = null,
        this.isRecorderEnded = !1,
        this.isVideoCliped = !1,
        this.bannerId = "1koj470oade37ge5f2",
        this.videoId = "f061jk4g0813jn88mi",
        this.insertId = "44a0b3e7ac9j606fd3",
        this.bannerAd = null,
        this.videoAd = null,
        this.click_video = !1,
        this.insertAd = null
    }
    return Object.defineProperty(t, "instance", {
        get: function() {
            return null == this._instance && (this._instance = new t),
            this._instance
        },
        enumerable: !1,
        configurable: !0
    }),
    t.prototype.getSystemInfoSync = function() {
        return tt.getSystemInfoSync()
    },
    t.prototype.is_douyin_active_banner = function() {
        return "ios" == this.systemInfo.platform ? n.Util.compareVersion(this.systemInfo.version, "11.7.0") > 0 : n.Util.compareVersion(this.systemInfo.version, "11.8.0") > 0
    },
    t.prototype.is_Douyin = function() {
        return "Douyin" == this.systemInfo.appName
    },
    t.prototype.is_ios = function() {
        return "ios" == this.systemInfo.platform
    },
    t.prototype.login_tt = function() {
        tt.login({
            force: !1,
            success: function(t) {
                console.log("login调用成功" + t.code + " " + t.anonymousCode),
                console.log("isLogin_tt: " + t.isLogin)
            },
            fail: function() {
                console.log("login调用失败")
            }
        })
    },
    t.prototype.get_tt_userInfo = function() {
        tt.getUserInfo({
            success: function(t) {
                console.log(JSON.stringify(t))
            },
            fail: function() {}
        })
    },
    t.prototype.update_version = function() {
        var t = tt.getUpdateManager();
        t.onUpdateReady(function() {
            tt.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启小游戏？",
                success: function(e) {
                    e.confirm && t.applyUpdate()
                }
            })
        }),
        t.onUpdateFailed(function(t) {
            console.log("版本下载失败原因", t),
            tt.showToast({
                title: "新版本下载失败，请稍后再试",
                icon: "none"
            })
        })
    },
    t.prototype.clipVideo = function() {
        var t = this;
        this.isVideoCliped || this.recorder.clipVideo({
            path: this.videoPath,
            timeRange: [30, 0],
            success: function(e) {
                t.videoPath = e.videoPath,
                t.isVideoCliped = !0
            },
            fail: function(t) {
                console.error(t)
            }
        })
    },
    t.prototype.recordVideoStart = function() {
        this.recorder.start({
            duration: 300
        })
    },
    t.prototype.recordVideoEnd = function() {
        this.isRecorderEnded || (this.recorder.stop(), this.recordingTime = new Date().getTime() - this.recordingTime, console.log("录屏结束: " + this.recordingTime), this.recordingTime <= 3e3 && i.default.show("录屏时长需大于3秒~"))
    },
    t.prototype.RecorderVideo_publish = function() {
        this.isVideoCliped ? this.shareVideo() : this.recordingTime > 3e3 ? this.shareVideo() : tt.showToast({
            title: "录屏失败：录屏时长低于 3 秒",
            icon: "none",
            duration: 1e3,
            success: function(t) {
                console.log("" + t)
            },
            fail: function() {
                console.log("showToast调用失败")
            }
        })
    },
    t.prototype.shareVideo = function() {
        this.videoPath ? "ios" == this.systemInfo.platform ? tt.shareVideo({
            videoPath: this.videoPath,
            success: function() {
                i.default.show("录屏发布成功"),
                console.log("录屏发布成功")
            },
            fail: function(t) {
                console.log(JSON.stringify(t)),
                tt.showToast({
                    title: "发布录屏失败！",
                    icon: "none",
                    duration: 1e3,
                    success: function() {},
                    fail: function() {}
                })
            }
        }) : tt.shareAppMessage({
            channel: "video",
            extra: {
                videoPath: this.videoPath
            },
            success: function() {
                i.default.show("录屏发布成功"),
                console.log("录屏发布成功")
            },
            fail: function(t) {
                console.log(JSON.stringify(t)),
                tt.showToast({
                    title: "发布录屏失败！",
                    icon: "none",
                    duration: 1e3,
                    success: function() {},
                    fail: function() {
                        console.log("showToast调用失败")
                    }
                })
            }
        }) : tt.showToast({
            title: "录屏文件发生错误!",
            icon: "none",
            duration: 1e3,
            success: function() {},
            fail: function() {
                console.log("showToast调用失败")
            }
        })
    },
    t.prototype.shareAppMsg = function() {
        tt.shareAppMessage({
            title: "",
            desc: "",
            imageUrl: "",
            query: "",
            success: function() {
                console.log("分享成功")
            },
            fail: function() {
                console.log("分享失败")
            }
        })
    },
    t.prototype.auto_recorder_publish = function() {},
    t.prototype.vibrateLong = function() {
        tt.vibrateLong({})
    },
    t.prototype.vibrateShort = function() {
        tt.vibrateShort({})
    },
    t.prototype.init = function() {
        var t = this;
        this.update_version(),
        this.systemInfo = this.getSystemInfoSync(),
        console.log(this.systemInfo),
        console.log("平台：" + this.systemInfo.appName),
        this.recorder = tt.getGameRecorderManager(),
        this.recorder.onStart(function() {
            console.log("录屏开始"),
            t.isVideoCliped = !1,
            t.isRecorderEnded = !1,
            t.videoPath = null,
            t.deltaTime = 0,
            t.recordingTime = new Date().getTime()
        }),
        this.recorder.onStop(function(e) {
            console.log("录屏结束： " + JSON.stringify(e)),
            t.videoPath = e.videoPath,
            t.isRecorderEnded = !0,
            t.clipVideo()
        }),
        this.login_tt(),
        tt.onShareAppMessage(function(t) {
            return console.log(t.channel),
            {
                title: "",
                imageUrl: "",
                query: "",
                success: function() {
                    console.log("分享成功")
                },
                fail: function(t) {
                    console.log("分享失败", t)
                }
            }
        })
    },
    t.prototype.showBanner = function(t) {
        var e = this;
        if (void 0 === t && (t = !1), !this.bannerAd || t) {
            this.bannerAd = tt.createBannerAd({
                adUnitId: this.bannerId,
                adIntervals: 30,
                style: {
                    left: 0,
                    top: 0,
                    width: 180
                }
            }),
            this.bannerAd && this.bannerAd.onResize(function(t) {
                e.bannerAd.style.top = e.systemInfo.windowHeight - t.height,
                e.bannerAd.style.left = (e.systemInfo.windowWidth - t.width) / 2,
                console.log("banner width: " + t.width),
                console.log("banner height: " + t.height),
                console.log("banner left: " + e.bannerAd.style.left),
                console.log("banner top: " + e.bannerAd.style.top)
            });
            var o = function() {
                e.bannerAd.show(),
                e.bannerAd.offLoad(o)
            };
            this.bannerAd && this.bannerAd.offLoad(o),
            this.bannerAd && this.bannerAd.onLoad(o)
        } else this.bannerAd && this.bannerAd.show()
    },
    t.prototype.hideBanner = function() {
        this.bannerAd && this.bannerAd.hide()
    },
    t.prototype.showHallBanner = function() {},
    t.prototype.hideHallBanner = function() {},
    t.prototype.showRewardVideo = function(t, e, o) {
        var n = this;
        if (this.videoAd || (this.videoAd = tt.createRewardedVideoAd({
            adUnitId: this.videoId
        })), !this.click_video) {
            this.click_video = !0;
            var a = function(o) {
                n.click_video = !1,
                o.isEnded ? t() : (e && e(), i.default.show("激励视频广告未看完，不发放奖励")),
                n.videoAd.offClose(a)
            };
            this.videoAd.offClose(a),
            this.videoAd.onClose(a);
            var r = function(t) {
                o && o(),
                n.click_video = !1,
                i.default.show("激励视频加载失败"),
                console.log(t.errMsg),
                n.videoAd.offError(r),
                n.videoAd.offClose(a)
            };
            this.videoAd.offError(r),
            this.videoAd.onError(r),
            this.videoAd.load().then(function() {
                n.videoAd.show()
            }).
            catch(function() {})
        }
    },
    t.prototype.showInsertAd = function(t, e) {
        var o = this;
        if ("Toutiao" == this.systemInfo.appName || this.is_Douyin()) {
            this.insertAd && (this.insertAd.destroy(), this.insertAd = null);
            var i = function() {
                e && e(),
                o.insertAd.offClose(i)
            };
            this.insertAd = tt.createInterstitialAd({
                adUnitId: this.insertId
            }),
            this.insertAd.load().then(function() {
                o.insertAd.show().then(function() {
                    o.hideBanner(),
                    t && t()
                }).
                catch(function(t) {
                    e && e(),
                    console.log("======================插屏显示失败: ============================="),
                    console.log(JSON.stringify(t))
                }),
                o.insertAd.onClose(i)
            }).
            catch(function(t) {
                e && e(),
                console.log(t)
            })
        }
    },
    t._instance = null,
    t
} ();
o.default = a